package com.itzyf.pokemondata

import android.view.View
import android.widget.TextView
import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import com.avos.avoscloud.*
import com.itzyf.pokemondata.bean.DbPokemon
import kotlinx.android.synthetic.main.activity_panel_detail.*

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
//        val appContext = InstrumentationRegistry.getTargetContext()
//        val avQuery = AVObject.createWithoutData("PokemonJsonDo", "5c375364756571006729d9a7")
//        avQuery.fetchInBackground("ExclusiveJsonDo", object : GetCallback<AVObject>() {
//            override fun done(avObject: AVObject?, e: AVException?) {
//              println(avObject)
//            }
//        })

//        val dongGuan = AVObject.createWithoutData("PokemonJsonDo", "5c375364756571006729d9a7")
//        dongGuan.fetchInBackground("ExclusiveJsonDo", object : GetCallback<AVObject>() {
//            override fun done(avObject: AVObject, e: AVException) {
//                // 获取广东省
//                val province = avObject.getAVObject<AVObject>("ExclusiveJsonDo")
//                print(province["name"])
//            }
//        })

        val pokemon = AVQuery<AVObject>("PokemonJsonDo")
        pokemon.whereContains("pokemonName","海皇牙")
        pokemon.findInBackground(object : FindCallback<AVObject>() {
            override fun done(avObjects: MutableList<AVObject>?, e: AVException?) {
                if (e != null) {
                    e.printStackTrace()
                }
                if (avObjects == null)
                    return
                for (avObject in avObjects) {
                    val pokemonName = avObject.getString("pokemonName")
                    val hp = avObject.getInt("hp")
                    val pa = avObject.getInt("pa")
                    val pd = avObject.getInt("pd")
                    val sa = avObject.getInt("sa")
                    val sd = avObject.getInt("sd")
                    val speed = avObject.getInt("speed")

                    println(
                        DbPokemon(
                            avObject.createdAt,
                            null,
                            hp,
                            avObject.objectId,
                            pa,
                            pd,
                            pokemonName,
                            sa,
                            sd,
                            avObject.getString("skin"),
                            speed,
                            avObject.updatedAt
                        )
                    )

                }
            }

        })
    }
}
